package com.group.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.commons.entity.Product;
import com.group.commons.entity.ProductCategory;
import com.group.commons.service.AdminService;
import com.group.commons.util.ResponseInfo;
import com.group.commons.util.ResponseStatus;
import com.group.product.dao.ProductCategoryDao;
import com.group.product.service.impl.ProductCategoryServiceImpl;
import com.group.product.service.impl.ProductServiceImpl;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author :spj
 * @date:2022/6/6
 * @description:
 */
@RestController
@RequestMapping("/product")
public class ProductCategoryController {
    @Resource
    ProductCategoryServiceImpl categoryService;

    @ApiOperation(value = "查询分类", notes = "查询所有")
    @PostMapping("/category/{page}/{pages}")
    public List<ProductCategory> getAllCategory(@PathVariable("page")int page,@PathVariable("pages")int pages,@RequestBody ProductCategory category){
        Page<ProductCategory> pagePlus = new Page<>(page, pages);
        return categoryService.findAllProductCategories(pagePlus,category);
    }

    @PostMapping("/category/{fid}")
    public Integer addCategory(@PathVariable("fid")int fid,@RequestBody ProductCategory category){
        return categoryService.addProductCategory(category,fid);
    }
    @PutMapping("/category")
    public Integer addCategory(@RequestBody ProductCategory category){
        return categoryService.changeCategory(category);
    }
    @DeleteMapping("/category/{id}")
    public Integer addCategory(@PathVariable("id")int id){
        return categoryService.deleteProductCategory(id);
    }
}
